<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>报价单</title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/list.css">
    <script>
   //检索 
   function searchListForm() {

        var params = $("#searchForm").serialize();
		$.post("${ctx}/settlement/single/searchUnrecordedList",params, function(result) {
			var listHtml = result["finance"];
			var pageHtml = result["page"];
			$("#listHtml").html(listHtml);
			$("#paging").html(pageHtml);
			
		}, 'json');
	} 
        
	 //重置
	function clean() {
		$("input").val("");
		$("select").val("");
		searchListForm();
	}   
	 
	
	function selectStyle() {
		//获取 iframe 数量 
    	var frLength = window.parent.frames.length;
    	//父画面下标 
    	var parentIndex = frLength-2;
    	var trSelectedLength = $("#listHtml tr.trSelected").length;
    	var trSelected = $("#listHtml tr.trSelected");
    	var selectHtml = window.parent.frames[parentIndex].$("#hiddenSelect").html();
    	var financeIdObj = window.parent.frames[parentIndex].$(".settleAccountsId");
    	var financeIdStr = "";
    	$.each(trSelected, function(i, item){
    		var html = "";
    		var hiddenHtml = "";
    		var existFlag = "false";
    		var financeId = $(item).find(".financeId").val();
    		$.each(financeIdObj, function(i, item){
    			if ($(item).val() == financeId) {
    				existFlag = "true";
    				return false;
				}
    		});
    		if (existFlag == "true") {
    			return true;
			}
    		financeIdStr = financeIdStr + financeId + ",";
    		var financeDate = $(item).find(".financeDate").val();
    		var accountsStatus = $(item).find(".accountsStatus").val();
    		var financePeriod = $(item).find(".financePeriod").text();
    		var financeCategory = $(item).find(".financeCategory").text();
    		var financeContractNo = $(item).find(".financeContractNo").text();
    		var financeCurrency = $(item).find(".financeCurrency").text();
    		var debitAmountHtml = $(item).find(".debitAmountHtml").text();
    		var creditAmountHtml = $(item).find(".creditAmountHtml").text();
    		var debitAmount = $(item).find(".debitAmount").val();
    		var creditAmount = $(item).find(".creditAmount").val();
    		var remarks = $(item).find(".remarks").text();
    		html += "<tr>";
    		html += "<td><p class='tab-no'><img src='/ls-qc/static/images/del_icon.png' style='width: 21px' onclick='deleteCurrentRow(this,"+financeId+");'></p></td>";
    		html += "<td><p class='width-100px'>"+financePeriod+"</p></td>";
    		html += "<td><p class='width-120px'>"+selectHtml+"</p></td>";
    		html += "<td><p class='width-100px'>"+financeCategory+"</p></td>";
    		html += "<td><p class='width-120px'>"+financeContractNo+"</p></td>";
    		html += "<td><p class='width-100px'>"+financeCurrency+"</p></td>";
    		html += "<td id='debitAmount' class='tab-debitAmount width-100px'>"+debitAmountHtml+"</td>";
    		html += "<td id='creditAmount' class='tab-creditAmount width-100px'>"+creditAmountHtml+"</td>";
    		html += "<td><p class='width-120px'><textarea style='width:120px' onblur='setValue(this);'>"+remarks+"</textarea></p></td>";
    		html += "<input type='hidden' class='voucherRemarks' name='voucherDetailEntity.voucherDetailList[tempIndex].voucherRemarks' value='"+remarks+"'/>";
    		html += "<input type='hidden' class='accountItem' name='voucherDetailEntity.voucherDetailList[tempIndex].accountItem' value=''/>";
    		html += "<input type='hidden' class='settleAccountsId' name='voucherDetailEntity.voucherDetailList[tempIndex].settleAccountsId' value='"+financeId+"'/>";
    		html += "<input type='hidden' name='voucherDetailEntity.voucherDetailList[tempIndex].settleAccountsDate' value='"+financeDate+"'/>";
    		html += "<input type='hidden' name='voucherDetailEntity.voucherDetailList[tempIndex].settleAccountsStatus' value='"+accountsStatus+"'/>";
    		html += "<input type='hidden' class='debitAmount' name='voucherDetailEntity.voucherDetailList[tempIndex].debitAmount' value='"+debitAmount+"'/>";
    		html += "<input type='hidden' class='creditAmount' name='voucherDetailEntity.voucherDetailList[tempIndex].creditAmount' value='"+creditAmount+"'/>";
    		html += "</tr>";
    		window.parent.frames[parentIndex].$("#listHtml").append(html);
    	});
    	<!-- 获取历史凭证 -->
    	$.post("${ctx}/accounting/voucher/findVoucherHistory?financeId="+financeIdStr,"", function(result) {
			$.each(result, function(i, item){
				var htmlHis = "";
				htmlHis += "<tr class='historyTr hsty-"+item.settleAccountsId+"'>";
				htmlHis += "<td><p class='tab-no historyNo'></p></td>";
				htmlHis += "<td><p class='width-100px'>"+item.financeEntity.financePeriodStr+"</p></td>";
				htmlHis += "<td><p class='width-120px'>"+item.accountItem+"</p></td>";
				htmlHis += "<td><p class='width-100px'>"+item.financeEntity.financeCategory+"</p></td>";
				htmlHis += "<td><p class='width-120px'>"+item.financeEntity.financeContractNo+"</p></td>";
				htmlHis += "<td><p class='width-100px'>"+item.financeEntity.financeCurrency+"</p></td>";
				htmlHis += "<td><p class='width-100px debitAmountHis'>"+item.debitAmount+"</p></td>";
				htmlHis += "<td><p class='width-100px creditAmountHis'>"+item.creditAmount+"</p></td>";
				htmlHis += "<td><p class='width-120px'>"+item.voucherRemarks+"</p></td>";
				htmlHis += "</tr>";
				window.parent.frames[parentIndex].$("#listHtmlHistory").append(htmlHis);
			});
	   		window.parent.frames[parentIndex].$("p>select").select2();
	   		window.parent.frames[parentIndex].sumAmount();
	   		window.parent.frames[parentIndex].onClickTd();
	   		closeWin();
		}, 'json');
	}
    //选择按钮事件
    function selectFunction(obj){
    	// 判断是否被选中
    	var bolSelected = $(obj).hasClass("trSelected");
    	if (bolSelected) {
    		$(obj).removeClass("trSelected");
    	} else {
    		$(obj).addClass("trSelected");
    	}
    	
    }
    </script>
    
</head>
<body style="min-width: 870px">
<form id="searchForm">
<input type = "hidden" id = "frameFlg" value="${quotation.frameFlg}"/>
<div class="layerHeader clearfix" style="width: 900px">
	<p class="headerTitle"><spring:message code="quotation_style_selectStyle" /></p>
	<div class="headerButton clearfix">
                <button type="button" onclick="searchListForm();"><spring:message code="quotation_style_search" /></button>
                <button type="button" onclick="clean();"><spring:message code="common_reset" /></button>
                <button type="button" onclick="selectStyle();"><spring:message code="quotation_style_selected" /></button>
                <button type="button" onclick="closeWin();"><spring:message code="quotation_style_cancle" /></button>
                </div>
</div>
<div class="listArea" style="width: 900px">
	<div class="listBg">
        <div class="searchArea clearfix">
            <div id="showHtml" class=" clearfix">
                <!--业务期间 -->
                <div class="searchInp clearfix">
                    <p>业务期间</p>
                    <input type="text" style="width: 70px;" id="dateYear" name="dateYear" class="laydate-icon" onclick="WdatePicker({el:this,dateFmt:'yyyy',onpicked:null})">
                    <p style="width: 25px;left: 5px;position: relative;">年</p>
                    <input type="text" style="width: 70px;" id="dateMonth" name="dateMonth" class="laydate-icon" onclick="WdatePicker({el:this,dateFmt:'MM',onpicked:null})">
                    <p style="width: 25px;left: 5px;position: relative;">月</p>
                </div>
                <!--业务类别 -->
                <c:set value="<%=ResourcesUtil.getConfig(\"finance_category\") %>" var="fCategoryList"/>
                <div class="searchInp clearfix">
                    <p>业务类别</p>
                    <select id="financeCategory" name="financeCategory" style="width: 120px;">
	                    <option value="">请选择</option>
	                    <c:forEach items="${fns:getDictList(fCategoryList) }" var="fCategory">
	                    	<option value="${fCategory.itemCode }-${fCategory.itemValue }">${fCategory.itemName }</option>
	                    </c:forEach>
                    </select>
                </div>
            </div>
                
        </div>
   
        <div class="tableArea tabBoxSm" >
            <div class="tableScroll tabSm" style="overflow: auto;height: 420px;width:860px">
                <table cellpadding="0" class="tableHead " >
                    <thead>
                    <tr>
                        <th><p class="width-50px"><spring:message code="handBook_head_no"/></p></th>
                        <th><p class="width-100px">业务期间</p></th>
                        <th><p class="width-80px">业务类别</p></th>
                        <th><p class="width-100px">业务号</p></th>
                        <th><p class="width-100px">货币类别</p></th>
                        <th><p class="width-100px">借方</p></th>
                        <th><p class="width-100px">贷方</p></th>
                        <th><p class="width-100px">备注</p></th>
                        <th><p class="width-100px">创建人员</p></th>
                    </tr>
                    </thead>
                </table>
                <table cellpadding="0" class="tableBody" >              
                    <tbody id = "listHtml">
                    </tbody>
                </table>
            </div>
            
        </div>
    </div>
    <div id = "paging" ></div>
</div>
</form>
<script type="text/javascript">
$(document).ready(function(){
	searchListForm();
	$("select").select2();
});
</script> 
</body>
</html>
	